import baseservice from '../common/baseservice.js';
export default {
	getPageData(self, successBack, errorBack) {
		baseservice.getPageData(self, self.apis.companyPage, self.searchcondition, function(res){
			self.tableData = res.data.list;
			self.total = res.data.total;
			for(let i=0;i< self.tableData.length;i++){
				if(self.tableData[i].companyShortIntro.length > 100) {
					self.tableData[i].companyShortIntro = self.tableData[i].companyShortIntro.substring(0, 100) + "...";
				}
			}			
		}, errorBack);
	},
	getModelData(self, id, successBack, errorBack) {
		baseservice.getModelData(self, self.apis.companyGet, id);
	},
	showDetail(self, row, title) {
		baseservice.showDetail(self, row, title);
	},
	getAllCompanys(self,successBack, errorBack){
		self.httptool.ajaxPost(self.apis.companyGetAll,{},function(res){
			successBack(res);
		});
	},
	handleSave(self, successBack, errorBack) {	
		let rule = [{
			name: 'companyLogo',
			label: '机构头像',
			rule: ['validateUpload_']
		},{
			name: 'companyName',
			label: '机构名称',
			rule: ['validateEmpty_']
		},{
			name: 'companyShortIntro',
			label: '机构简介',
			rule: ['validateEmpty_']
		},{
			name: 'companyDesc',
			label: '机构描述',
			rule: ['validateEmpty_']
		}];
		
		if(!self.validatetool.validate(self, self.modelData, rule)) {
			return;
		}
		debugger;
		let requestUrl = self.apis.companyAdd;
		let msg = '添加成功';
		if(self.modelData.id > 0) {
			requestUrl = self.apis.companyUpdate;
			msg = '修改成功';
		}
		baseservice.handleSave(self,requestUrl,self.modelData,msg);				
	}
}